package com.whut.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whut.enums.EquipState;
import com.whut.mapper.*;
import com.whut.model.*;
import com.whut.service.EquipService;
import com.whut.service.NewFuzzyService;
import com.whut.v_model.ProblemCollectDetail;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ReflectionUtils;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;
import java.text.SimpleDateFormat;

/**
 * @Author chr
 * @Date 2020/6/1910:55
 * @ClassName EquipSeriveImpl
 * @Description TODO
 */
@Service("EquipService")
public class EquipServiceImpl implements EquipService {

    @Resource
    private ProblemCollectDetailMapper problemCollectDetailMapper;
    @Resource
    private NewProblemCollectDetailMapper newProblemCollectDetailMapper;
    @Resource
    private UncheckeditemsMapper uncheckeditemsMapper;
    @Resource
    private NewprefixsystemMapper newprefixsystemMapper;
    @Resource
    private MachineinfoMapper machineinfoMapper;
    @Resource
    private NoproblemitemMapper noproblemitemMapper;
    @Resource
    private ContracttaskprojectMapper contracttaskprojectMapper;
    @Resource
    private ContracttaskacceptMapper contracttaskacceptMapper;
    @Resource
    private ContractchecktaskMapper contractchecktaskMapper;
    @Resource
    private NewFuzzyService newFuzzyService;
    @Resource
    private EquipscoreMapper equipscoreMapper;
    @Resource
    private PrefixsystemMapper prefixsystemMapper;


    /**
     * @Author chenhuanru
     * @Description //获取单台设备分数及该类设备分数
     * @Date 17:53 2020/6/21
     * @Param [equipNums, checkId, fourthId]
     * @return java.lang.Object
     **/



    @Override
    public Object getEquipCheckResult(String equipNums, int checkId, int fourthId) {
        //System.out.println("前台数据"+equipNums);
        JSONArray equipList =JSON.parseArray(equipNums);
        List<Object> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<String, Object>();
        DecimalFormat df = new DecimalFormat("0.00");
        List<Map<String,Object>> list2 = new ArrayList<Map<String,Object>>();
        String equipType = newprefixsystemMapper.getName4ByName4Id(fourthId);
        for(int i=0;i<equipList.size();i++){
            Map<String, Object> map1 = new HashMap<String, Object>();

            String eqipNum = equipList.getString(i);
            map1.put("eqipNum",eqipNum);
            List<Map<String,Object>> checkedList = new ArrayList<Map<String,Object>>();

            //获取有问题的检查项
            List<ProblemCollectDetail> promblemList = problemCollectDetailMapper.getEquipProblems(eqipNum,checkId,fourthId);
            for(int j=0;j<promblemList.size();j++){
                ProblemCollectDetail problem = promblemList.get(j);
                Map<String, Object> map2 = new HashMap<String, Object>();
                //DecimalFormat df = new DecimalFormat("0.00");
                map2.put("pName56",problem.getpName6()+"("+problem.getpName5()+")");
                map2.put("point",Double.parseDouble(problem.getPoint6())-Double.parseDouble(problem.getReducePoint()));
                map2.put("type","检查发现问题");
                map2.put("total",Double.parseDouble(problem.getPoint6()));
                checkedList.add(map2);
            }
            // 检查没问题的项
            // 获取排除的项
            // List<Uncheckeditems> noProblemItems = uncheckeditemsMapper.getEquipNoProblem(checkId,fourthId);
            // for(int j=0;j<noProblemItems.size();j++){
            //     String unCheckedpName6 = newprefixsystemMapper.getName4ByName4Id(noProblemItems.get(j).getSixthId());
            //     int unCheckedFifthId = newprefixsystemMapper.getFather(noProblemItems.get(j).getSixthId()).getPreNum();
            //     String unCheckedpName5 = newprefixsystemMapper.getName4ByName4Id(unCheckedFifthId);
            //     Map<String, Object> map2 = new HashMap<String, Object>();
            //     map2.put("pName56",unCheckedpName6+"("+unCheckedpName5+")");
            //     map2.put("point",Double.parseDouble(newprefixsystemMapper.getPoint4ByPoint4Id(noProblemItems.get(j).getSixthId())));
            //     map2.put("type","检查没有问题");
            //     map2.put("total",Double.parseDouble(newprefixsystemMapper.getPoint4ByPoint4Id(noProblemItems.get(j).getSixthId())));
            //     checkedList.add(map2);
            // }
            //获取无问题项第六级id
            List<Integer> noProblemSixId = noproblemitemMapper.getNoProblemSixId(eqipNum,checkId,fourthId);

            for(int j=0;j<noProblemSixId.size();j++){
                String unCheckedpName6 = newprefixsystemMapper.getName4ByName4Id(noProblemSixId.get(j));
                int unCheckedFifthId = newprefixsystemMapper.getFather(noProblemSixId.get(j)).getPreNum();
                String unCheckedpName5 = newprefixsystemMapper.getName4ByName4Id(unCheckedFifthId);
                Map<String, Object> map2 = new HashMap<String, Object>();
                map2.put("pName56",unCheckedpName6+"("+unCheckedpName5+")");
                map2.put("point",Double.parseDouble(newprefixsystemMapper.getPoint4ByPoint4Id(noProblemSixId.get(j))));
                map2.put("type","检查没有问题");
                map2.put("total",Double.parseDouble(newprefixsystemMapper.getPoint4ByPoint4Id(noProblemSixId.get(j))));
                checkedList.add(map2);
            }
            map1.put("checkedList",checkedList);
            double allTotal=0;
            double allPoint=0;
            for(Map<String,Object> map3 : checkedList){
                allPoint+=(double) map3.get("point");
                allTotal+=(double) map3.get("total");
            }
            double resultPoint = allPoint/allTotal*100;

            //综合分
            String result=df.format(resultPoint);
            // 理想得分
            String idealPoint=df.format(allTotal);
            //实际得分
            String realPoint = df.format(allPoint);
            map1.put("idealPoint",idealPoint);
            map1.put("realPoint",realPoint);
            map1.put("resultPoint",result);
            list2.add(map1);
        }
        map.put("equipResult",list2);
        //计算平均分
        double sum=0;
        for(Map<String,Object> mm:list2){
            sum+=Double.parseDouble((String) mm.get("resultPoint"));
        }
        double avlPoint = sum/list2.size();
        map.put("equipType",equipType);
        map.put("avlPoint",df.format(avlPoint));
        list.add(map);
        return list;
    }

    /**
     * @author: liukang
     * @Description: 导入excel文件
     * @date: 2020/7/12 19:44
     * @param:
     * @return:
     */
    @Override
    public String importMachineInfoExcel(String filePath,int projectId,int projectType,int equipType,int machineType) throws ParseException {
        //根据filePath路径实例化Workbook
        Workbook workbook = openExcel(filePath);
        //拿到这个workbook里面的表的数目
        int sheetCount=workbook.getNumberOfSheets();
        DataFormatter dataFormatter = new DataFormatter();
        String machineName = newprefixsystemMapper.getName4ByName4Id(machineType);
        System.out.println(machineName);
        String projectName = contracttaskprojectMapper.getProjectNameByProjectId(projectId);

        if(machineName.equals("塔式起重机")){
            //getSheetAt、getRow、getCell、getFirstCellNum都是从0开始算起；
            // getLastCellNum最后元素索引加1，即表示此行元素个数;填满的话同getPhysicalNumberOfCells
            // 合并的单元格看合并之前的位置22；
            //按索引取表
            Sheet sheet = workbook.getSheetAt(0);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=30;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==30){
                    if(field.equals("workersIdNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("塔式起重机")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }
            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            //依据行数遍历
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
            for (int i =0 ;i<EquipNum.size();i++ ){
                if( row.getCell(2).getStringCellValue() == EquipNum.get(i)){
                    exit=true;
                    break;
                }
              }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，19
                if(
                    row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }


                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 30;cellIndex++){
                    String stringData = null;
                    Integer integerData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==20 || cellIndex==21 ||cellIndex==22 ||cellIndex==25){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else if(cellIndex==23){
                        Double data = row.getCell(cellIndex).getNumericCellValue();
                        integerData = (Integer) data.intValue();
                        //System.out.println("index:"+cellIndex+"  value:"+integerData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            //未知错误
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            //可以优化的代码
                            Integer numData=null;
                            if(stringData.equals(EquipState.record.value)){
                                numData=EquipState.record.key;
                            }else if(stringData.equals(EquipState.use.value)){
                                numData=EquipState.use.key;
                            }else if(stringData.equals(EquipState.pause.value)){
                                numData=EquipState.pause.key;
                            }else if(stringData.equals(EquipState.demolish.value)){
                                numData=EquipState.demolish.key;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setInitialHight(doubleData);
                            break;
                        case 21:
                            machineinfo.setMaxInstallHight(doubleData);
                            break;
                        case 22:
                            machineinfo.setEndInstallHight(doubleData);
                            break;
                        case 23:
                            machineinfo.setIncreaseTimes(integerData);
                            break;
                        case 24:
                            machineinfo.setLastIncreaseDate(stringData);
                            break;
                        case 25:
                            machineinfo.setUseHeight(doubleData);
                            break;
                        case 26:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 27:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 28:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                        case 29:
                            machineinfo.setIncreaseOperatorId(stringData);
                            break;
                        case 30:
                            machineinfo.setWorkersIdNum(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("施工升降机")){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(1);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            System.out.println(sheet.getLastRowNum());
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=29;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==29){
                    if(field.equals("increaseOperatorId")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("施工升降机")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }


            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，19
                if(
                    row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 29;cellIndex++){
                    String stringData = null;
                    Integer integerData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==20 || cellIndex==21 ||cellIndex==22 ||cellIndex==25){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else if(cellIndex==23){
                        Double data = row.getCell(cellIndex).getNumericCellValue();
                        integerData = (Integer) data.intValue();
                        //System.out.println("index:"+cellIndex+"  value:"+integerData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            Integer numData=null;
                            if(stringData.equals("未备案")){
                                numData=1;
                            }else if(stringData.equals("使用中")){
                                numData=2;
                            }else if(stringData.equals("已报停")){
                                numData=3;
                            }else if(stringData.equals("已拆除")){
                                numData=4;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setInitialHight(doubleData);
                            break;
                        case 21:
                            machineinfo.setMaxInstallHight(doubleData);
                            break;
                        case 22:
                            machineinfo.setEndInstallHight(doubleData);
                            break;
                        case 23:
                            machineinfo.setIncreaseTimes(integerData);
                            break;
                        case 24:
                            machineinfo.setLastIncreaseDate(stringData);
                            break;
                        case 25:
                            machineinfo.setUseHeight(doubleData);
                            break;
                        case 26:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 27:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 28:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                        case 29:
                            machineinfo.setIncreaseOperatorId(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("物料提升机")){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(2);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=27;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==27){
                    if(field.equals("demolitionPersonnelId")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("物料提升机")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }


            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，19
                if(
                        row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 27;cellIndex++){
                    String stringData = null;
                    Integer integerData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==20 || cellIndex==21 ||cellIndex==24 ){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else if(cellIndex==22){
                        Double data = row.getCell(cellIndex).getNumericCellValue();
                        integerData = (Integer) data.intValue();
                        //System.out.println("index:"+cellIndex+"  value:"+integerData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            //未知错误
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            //目前没有这个字段
                            Integer numData=null;
                            if(stringData.equals("未备案")){
                                numData=1;
                            }else if(stringData.equals("使用中")){
                                numData=2;
                            }else if(stringData.equals("已报停")){
                                numData=3;
                            }else if(stringData.equals("已拆除")){
                                numData=4;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setInstallHight(doubleData);
                            break;
                        case 21:
                            machineinfo.setEndInstallHight(doubleData);
                            break;
                        case 22:
                            machineinfo.setIncreaseTimes(integerData);
                            break;
                        case 23:
                            machineinfo.setLastIncreaseDate(stringData);
                            break;
                        case 24:
                            machineinfo.setUseHeight(doubleData);
                            break;
                        case 25:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 26:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 27:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("桥式起重机") || machineName.equals("门式起重机")){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(3);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=23;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==23){
                    if(field.equals("workersIdNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("桥式/门式起重机") ){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }


            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，19
                if(
                        row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 23;cellIndex++){
                    String stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                    //System.out.println("index:"+cellIndex+"  value:"+stringData);

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            //未知错误
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            //目前没有这个字段
                            Integer numData=null;
                            if(stringData.equals("未备案")){
                                numData=1;
                            }else if(stringData.equals("使用中")){
                                numData=2;
                            }else if(stringData.equals("已报停")){
                                numData=3;
                            }else if(stringData.equals("已拆除")){
                                numData=4;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 21:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 22:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                        case 23:
                            machineinfo.setWorkersIdNum(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("附着式升降脚手架")){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(4);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=28;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==28){
                    if(field.equals("demolitionPersonnelId")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("附着式升降脚手架")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }
            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            //依据行数遍历
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);
                //验证必填项2，4，19
                if(
                    row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 28;cellIndex++){
                    String stringData = null;
                    Integer integerData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==20 || cellIndex==22 ||cellIndex==23 ){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else if(cellIndex==24){
                        Double data = row.getCell(cellIndex).getNumericCellValue();
                        integerData = (Integer) data.intValue();
                        //System.out.println("index:"+cellIndex+"  value:"+integerData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            //未知错误
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            //目前没有这个字段
                            Integer numData=null;
                            if(stringData.equals("未备案")){
                                numData=1;
                            }else if(stringData.equals("使用中")){
                                numData=2;
                            }else if(stringData.equals("已报停")){
                                numData=3;
                            }else if(stringData.equals("已拆除")){
                                numData=4;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setInitialHight(doubleData);
                            break;
                        case 21:
                            machineinfo.setInstallTime(stringData);
                            break;
                        case 22:
                            machineinfo.setFrameHeight(doubleData);
                            break;
                        case 23:
                            machineinfo.setEndInstallHight(doubleData);
                            break;
                        case 24:
                            machineinfo.setIncreaseTimes(integerData);
                            break;
                        case 25:
                            machineinfo.setLastIncreaseDate(stringData);
                            break;
                        case 26:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 27:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 28:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                    }
                }


                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("流动式起重机") || machineName.equals("汽车起重机") ||machineName.equals("轮胎起重机") ||machineName.equals("履带起重机") ){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(5);
            String sheetName = sheet.getSheetName();
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=16;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==6){
                    if(field.equals("useUnit")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==16){
                    if(field.equals("workersIdNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("流动式起重机")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }
            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，13
                if(
                    row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                    row.getCell(13).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 16;cellIndex++){
                    String stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                    //System.out.println("index:"+cellIndex+"  value:"+stringData);

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            //目前没有这个字段
                            Integer numData1=null;
                            if(stringData.equals("使用")){
                                numData1=1;
                            }else if(stringData.equals("退场")){
                                numData1=2;
                            }
                            machineinfo.setEquipState(numData1);
                            break;
                        case 14:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 16:
                            machineinfo.setWorkersIdNum(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else if(machineName.equals("高处作业吊篮")){
            //按索引取表
            Sheet sheet = workbook.getSheetAt(6);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=16;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==7){
                    if(field.equals("productionUnit")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==16){
                    if(field.equals("demolitionPersonnelId")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表中设备类型验证
            Row equipRow = sheet.getRow(2);
            Cell equipCell=equipRow.getCell(2);
            String equipField = equipCell.getRichStringCellValue().getString().trim();
            if(!equipField.equals("高处作业吊篮")){
                fieldVerify=false;
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表的格式错误";
            }

            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，3，13
                if(
                        row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(3).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(13).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 16;cellIndex++){
                    String stringData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==14){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            Integer numData=null;
                            if(stringData.equals("安装")){
                                numData=1;
                            }else if(stringData.equals("使用")){
                                numData=2;
                            }else if(stringData.equals("拆除")){
                                numData=3;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 14:
                            machineinfo.setInstallHight(doubleData);
                            break;
                        case 15:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 16:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                    }
                }

                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }
        else {
            //通用模板
            //按索引取表
            Sheet sheet = workbook.getSheetAt(7);
            //System.out.println("表名："+sheetName);

            //j从第4行开始，遍历到表的最后一行。
            //对workbook进行预处理，删掉中间为空的行。两个处理方法。
            for (int j = 7; j < sheet.getLastRowNum();){
                //拿到表sheet的第j行，Row类型的r
                Row r = sheet.getRow(j);

                //1、行为null
                if(r == null){
                    //因为此行为空，所以把j+1行到最后一行整体往上移一行
                    sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    continue;
                }

                //2、行里单元格全为空
                //flag标记，如果有非空的单元格，则为true。遍历完了之后还为false，即整行都是空的。
                boolean flag = false;
                //遍历行r，c为单元格
                for(Cell c:r){
                    //过时的方法和属性。
                    // cellType有：_NONE、NUMERIC、STRING、FORMULA、BLANK、BOOLEAN、ERROR
                    if(c.getCellTypeEnum() != CellType.BLANK){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    j++;
                    continue;
                } else{
                    if(j == sheet.getLastRowNum()) {
                        //如果是最后一行，直接移除即可
                        sheet.removeRow(r);
                    } else {
                        //删除此行，即把j+1行到最后一行整体往上移一行
                        sheet.shiftRows(j+1, sheet.getLastRowNum(),-1);
                    }
                }
            }

            //可以对表先做一遍校验，检查表中是不是写的对应字段
            Row fieldRow = sheet.getRow(5);
            boolean fieldVerify=true;
            for(int cellIndex=1;cellIndex <=30;cellIndex++){
                Cell cell=fieldRow.getCell(cellIndex);
                //取字符串类型数据
                String field = cell.getRichStringCellValue().getString().trim();
                //对字段名进行抽样验证
                if (cellIndex==1 ){
                    if(field.equals("equipModel")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if(cellIndex==16){
                    if(field.equals("eqiupRegistNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }else if (cellIndex==30){
                    if(field.equals("workersIdNum")){
                        continue;
                    }else {
                        fieldVerify=false;
                    }
                }
            }
            //表不符合要求
            if(!fieldVerify){
                return "error：录入表格式错误";
            }

            //表sheet的行数
            int rowCount=sheet.getLastRowNum();
            Boolean exit =false;
            //设备编号已存在不能录入
            for(int rowindex=7;rowindex<rowCount;rowindex++)
            {
                Row row=sheet.getRow(rowindex);
                List<String> EquipNum = new ArrayList<String>();
                EquipNum= machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
                for (int i =0 ;i<EquipNum.size();i++ ){
                    if( row.getCell(2).getStringCellValue().equals(EquipNum.get(i))){
                        exit=true;
                        break;
                    }
                }
            }
            if(exit){
                return "error：录入设备中设备编号已存在";
            }
            //依据行数遍历
            for(int rowindex=7;rowindex<rowCount;rowindex++){
                MachineInfo machineinfo = new MachineInfo();
                Row row=sheet.getRow(rowindex);

                //验证必填项2，4，19
                if(
                        row.getCell(2).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(4).getCellTypeEnum() == CellType.BLANK ||
                                row.getCell(19).getCellTypeEnum() == CellType.BLANK
                ){
                    continue;
                }

                //遍历此行的单元格，根据单元格的索引解析并存储数据
                for(int cellIndex=1;cellIndex <= 30;cellIndex++){
                    String stringData = null;
                    Integer integerData = null;
                    Double doubleData = null;
                    //根据要存的数据类型，取此单元格的数据
                    if(cellIndex==20 || cellIndex==21 ||cellIndex==22 ||cellIndex==25){
                        doubleData =  (Double) row.getCell(cellIndex).getNumericCellValue();
                        //System.out.println("index:"+cellIndex+"  value:"+doubleData);
                    }else if(cellIndex==23){
                        Double data = row.getCell(cellIndex).getNumericCellValue();
                        integerData = (Integer) data.intValue();
                        //System.out.println("index:"+cellIndex+"  value:"+integerData);
                    }else {
                        stringData = dataFormatter.formatCellValue(row.getCell(cellIndex));
                        //System.out.println("index:"+cellIndex+"  value:"+stringData);
                    }

                    //存单元格数据的逻辑
                    switch (cellIndex){
                        case 1:
                            machineinfo.setEquipModel(stringData);
                            break;
                        case 2:
                            machineinfo.setEquipNum(stringData);
                            break;
                        case 3:
                            machineinfo.setFactoryNum(stringData);
                            break;
                        case 4:
                            machineinfo.setFactoryDate(stringData);
                            break;
                        case 5:
                            machineinfo.setEndDate(stringData);
                            break;
                        case 6:
                            machineinfo.setUseUnit(stringData);
                            break;
                        case 7:
                            machineinfo.setProductionUnit(stringData);
                            break;
                        case 8:
                            machineinfo.setRentalUnit(stringData);
                            break;
                        case 9:
                            machineinfo.setMaintenanceUnit(stringData);
                            break;
                        case 10:
                            machineinfo.setInstallRemoveUnit(stringData);
                            break;
                        case 11:
                            machineinfo.setDetectionUnit(stringData);
                            break;
                        case 12:
                            machineinfo.setDetectDate(stringData);
                            break;
                        case 13:
                            machineinfo.setRegistNum(stringData);
                            break;
                        case 14:
                            machineinfo.setEquipRegistDate(stringData);
                            break;
                        case 15:
                            machineinfo.setEquipRegistValidDate(stringData);
                            break;
                        case 16:
                            //未知错误
                            machineinfo.setEquipRegistNum(stringData);
                            break;
                        case 17:
                            machineinfo.setUseRegistDate(stringData);
                            break;
                        case 18:
                            machineinfo.setUseRegistEndDate(stringData);
                            break;
                        case 19:
                            //目前没有这个字段
                            Integer numData=null;
                            if(stringData.equals("未备案")){
                                numData=1;
                            }else if(stringData.equals("使用中")){
                                numData=2;
                            }else if(stringData.equals("已报停")){
                                numData=3;
                            }else if(stringData.equals("已拆除")){
                                numData=4;
                            }
                            machineinfo.setEquipState(numData);
                            break;
                        case 20:
                            machineinfo.setInitialHight(doubleData);
                            break;
                        case 21:
                            machineinfo.setMaxInstallHight(doubleData);
                            break;
                        case 22:
                            machineinfo.setEndInstallHight(doubleData);
                            break;
                        case 23:
                            machineinfo.setIncreaseTimes(integerData);
                            break;
                        case 24:
                            machineinfo.setLastIncreaseDate(stringData);
                            break;
                        case 25:
                            machineinfo.setUseHeight(doubleData);
                            break;
                        case 26:
                            machineinfo.setAcceptanceDate(stringData);
                            break;
                        case 27:
                            machineinfo.setEquipmentOperatorId(stringData);
                            break;
                        case 28:
                            machineinfo.setDemolitionPersonnelId(stringData);
                            break;
                        case 29:
                            machineinfo.setIncreaseOperatorId(stringData);
                            break;
                        case 30:
                            machineinfo.setWorkersIdNum(stringData);
                            break;
                    }
                }

                //根据当前时间和出厂日期来计算使用时间
                String factoryDate = dataFormatter.formatCellValue(row.getCell(4));
                String useDate = countDays(factoryDate);
                machineinfo.setUseDate(useDate);

                //根据使用登记有效期截止日期和使用登记日期来计算机使用登记有效期
                String useRegistDate = dataFormatter.formatCellValue(row.getCell(17));
                String useRegistEndDate = dataFormatter.formatCellValue(row.getCell(18));
                String useRegistValidDate = countDays(useRegistDate,useRegistEndDate);
                machineinfo.setUseRegistValidDate(useRegistValidDate);


                //存两个时间
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                machineinfo.setNewCreatTime(formatter.format(date));
                machineinfo.setLastEditTime(formatter.format(date));

                //存工程id、工程名称；体系2、3、4级对应的projectType、equipType、machineType
                machineinfo.setProjectId(projectId);
                machineinfo.setProjectName(projectName);
                machineinfo.setProjectType(String.valueOf(projectType));
                machineinfo.setEquipType(equipType);
                machineinfo.setMachineType(machineType);

                machineinfoMapper.insertN(machineinfo);
            }
        }

        return "success：文件导入成功！";
    }

    /**
     * @author: liukang
     * @Description: 一个参数，计算当前时间和传入时间的时间差
     * @date: 2020/7/21 23:01
     * @param:
     * @return: X年X天
     */
    private String countDays(String time) throws ParseException {
        SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");
        if(StringUtils.isNotBlank(time)){
            Date DateTime = dataFormat.parse(time);
            Date nowDatetime = new Date();
            Long SpanTimeStamp = nowDatetime.getTime()-DateTime.getTime();
            int SpanTimeNum = Math.round(Math.abs(SpanTimeStamp)/(24 * 3600 * 1000));
            int yearsNum = SpanTimeNum / 365;
            int daysNum = SpanTimeNum % 365;
            String a = null;
            if(yearsNum==0){
                a = daysNum+"天";
            }else {
                a = yearsNum+"年"+daysNum+"天";
            }
            return a;
        }else {
            return "";
        }
    }

    /**
     * @author: liukang
     * @Description: 两个参数，计算两个时间的时间差
     * @date: 2020/7/21 23:00
     * @param:
     * @return: X年X天
     */
    private String countDays(String timeA,String timeB) throws ParseException {
        SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");
        if(StringUtils.isNotBlank(timeA) && StringUtils.isNotBlank(timeB)){
            Date DateTimeA = dataFormat.parse(timeA);
            Date DateTimeB = dataFormat.parse(timeB);
            Long SpanTimeStamp = DateTimeB.getTime()-DateTimeA.getTime();
            int SpanTimeNum = Math.round(Math.abs(SpanTimeStamp)/(24 * 3600 * 1000));
            int yearsNum = SpanTimeNum / 365;
            int daysNum = SpanTimeNum % 365;
            String a = null;
            if(yearsNum==0){
                a = daysNum+"天";
            }else {
                a = yearsNum+"年"+daysNum+"天";
            }
            return a;
        }else {
            return "";
        }
    }

    /**
     * @author: liukang
     * @Description: 打开excel文件
     * @date: 2020/7/21 23:01
     * @param: 
     * @return: Workbook
     */
    private Workbook openExcel(String ExcelName){
        InputStream inp = null;
        try{
            inp = new FileInputStream(ExcelName);
        }catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
        Workbook workbook = null;
        try {
            workbook = WorkbookFactory.create(inp);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return workbook;
    }

    /**
     * @author: liukang
     * @Description: 录入
     * @date: 2020/6/21 11:08
     * @param: machineinfo
     * @return: "success" or "error"
     */
    @Override
    public String saveMachineInfo(MachineInfo machineinfo){
        try{
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date = new Date(System.currentTimeMillis());
            machineinfo.setNewCreatTime(formatter.format(date));
            machineinfo.setLastEditTime(formatter.format(date));
            machineinfoMapper.insertN(machineinfo);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * @author: liukang
     * @Description: 真删除
     * @date: 2020/6/21 11:08
     * @param: mKey
     * @return: "success" or "error"
     */
    @Override
    public String deleteMachineInfo(Integer mKey){
        try{
            machineinfoMapper.deleteByPrimaryKey(mKey);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * @author: liukang
     * @Description: 假删除
     * @date: 2020/6/21 11:08
     * @param: mKey
     * @return: "success" or "error"
     */
    @Override
    public String deleteMachInfoByNY(Integer mKey){
        try{
            MachineInfo machineinfo = machineinfoMapper.selectByPrimaryKeyN(mKey);
            machineinfo.setIsDelete("Y");
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date = new Date(System.currentTimeMillis());
            machineinfo.setLastEditTime(formatter.format(date));
            machineinfoMapper.updateByPrimaryKey(machineinfo);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * @author: liukang
     * @Description: 编辑
     * @date: 2020/6/21 11:04
     * @param: machineinfo
     * @return: "success" or "error"
     */
    @Override
    public String updateMachineInfo(MachineInfo machineinfo){
        try{
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date = new Date(System.currentTimeMillis());
            machineinfo.setLastEditTime(formatter.format(date));
            machineinfoMapper.updateByPrimaryKeySelective(machineinfo);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * @author: liukang
     * @Description: 拿表里的所有信息
     * @date: 2020/6/21 12:25
     * @param: pageNum，pageSize
     * @return: List<MachineInfo>
     */
    @Override
    public Object getMachineInfoByPage(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MachineInfo> allMachine = machineinfoMapper.getAllMachine();
        PageInfo pageInfo = new PageInfo(allMachine);
        return pageInfo;
    }

    /**
     * @author: liukang
     * @Description: 搜索时调用的方法，根据搜索参数拿到数据
     * @date: 2020/6/21 11:04
     * @param: searchParams，pageNum，pageSize
     * @return: List<MachineInfo>
     */
    @Override
    public Object getMachineInfoBySearchParams(String searchParams,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MachineInfo> list = machineinfoMapper.getMachineInfoBySearchParams(searchParams);
        PageInfo pageInfo = new PageInfo(list);
        return  pageInfo;
    }

    /**
     * @author: liukang
     * @Description: 根据工程id获取信息，即展示所有信息时调用的方法
     * @date: 2020/6/21 11:05
     * @param: projectName，pageNum，pageSize
     * @return: List<MachineInfo>
     */
    @Override
    public Object getMachineInfoByProjectId(Integer projectId,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MachineInfo> list = machineinfoMapper.getMachineInfoByProjectId(projectId);
        PageInfo pageInfo = new PageInfo(list);
        return  pageInfo;
    }

    /**
     * @author: liukang
     * @Description: 根据工程id和设备类型获取信息，即下拉框选择设备类型时调用此方法
     * @date: 2020/6/21 11:07
     * @param: projectName，equipType，pageNum，pageSize
     * @return: List<MachineInfo>
     */
    @Override
    public Object getMachineInfoByEquipType(Integer projectId,Integer machineType,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MachineInfo> list = machineinfoMapper.getMachineInfoByEquipType(projectId,machineType);
        PageInfo pageInfo = new PageInfo(list);
        System.out.println(pageInfo);
        return  pageInfo;
    }
    /**
     * @author xiaxing
     *
     * @date 2021/3/17 9:32
     * @param: (projectId,equipType,pageNum,pageSize,)
     * @return List<MachineInfo>
     */
    public Object getMachineInfoByProjectIdAndEquipType(Integer projectId,Integer equipType,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MachineInfo> list = machineinfoMapper.getAllByProjectIdAndEquipType(projectId,equipType);
        PageInfo pageInfo = new PageInfo(list);
        System.out.println(pageInfo);
        return  pageInfo;
    }

    @Override
    public Object getEquipNUmByProjectIdAndEquipType(Integer projectId, Integer equipType) {

        return machineinfoMapper.getEquipNUmByProjectIdAndEquipType(projectId,equipType);
    }


    /**
     * @author: liukang
     * @Description: 在体系里根据number拿到parametername
     * @date: 2020/7/23 12:23
     * @param:
     * @return:
     */
    @Override
    public String getName4ByName4Id(int number){
        return newprefixsystemMapper.getName4ByName4Id(number);
    }

    @Override
    public Object getNoPromblemEquipNum(int checkId, int fourthId) {
        List<Object> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<String, Object>();
        // List<Uncheckeditems> noPromblems = uncheckeditemsMapper.getNoPromblemEquipNum(checkId,fourthId);
        Set result = new HashSet<String>();
        // for(int i=0;i<noPromblems.size();i++){
        //     String Nums = noPromblems.get(i).getReserve1();
        //     if(null!=Nums&&!"".equals(Nums)){
        //         JSONArray equipList =JSON.parseArray(Nums);
        //         Set<String> strSet = new HashSet(Arrays.asList(equipList.toArray()));
        //         result.addAll(strSet);
        //     }
        //
        //
        //     // System.out.println(Arrays.toString(str));
        // }
        List<String> item = noproblemitemMapper.getNoProblemEquipNum(checkId,fourthId);
        if(item.size()!=0){
            for(int j=0;j<item.size();j++){
                String Nums=item.get(j);
                if(null!=Nums&&!"".equals(Nums)){
                            String[] equipList =Nums.split(",");
                            Set<String> strSet = new HashSet(Arrays.asList(equipList));
                            result.addAll(strSet);
                        }
                System.out.println(Nums);
            }
        }
        List<String> result1 = new ArrayList<>(result);
        map.put("noProblemNums",result1);
        list.add(map);
        return list;
    }

    /**
     * @author： wenyihan
     * 根据委托方id获取项目信息
     * @date： 22:12 2020/6/22
     * @param： [contractId]
     * @return： java.lang.Object
    */
    @Override
    public List<ContractCheckTask> getProjectNameByTaskId(int taskId) {
        return contractchecktaskMapper.getAllByTaskId(taskId);
    }

    /**
     * @author： wenyihan
     * 获取项目类别
     * @date： 15:53 2020/6/27
     * @param： [projectId]
     * @return： java.lang.String
    */
    @Override
    public String getProjectCategoryByProjectId(int projectId) {
        return contracttaskprojectMapper.getProjectCategoryByProjectId(projectId);
    }

    /**
     * @author： wenyihan
     * 通过项目id获取项目名称
     * @date： 15:53 2020/6/27
     * @param： [projectId]
     * @return： java.lang.String
    */
    @Override
    public String getProjectNameByProjectId(int projectId) {
        return contracttaskprojectMapper.getProjectNameByProjectId(projectId);
    }

    @Override
    public Object getEquipUncheckedItems(String eqipNum, int checkId, int fourthId) {
        List<Object> list = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        DecimalFormat df = new DecimalFormat("0.00");
        List<Map<String,Object>> UncheckedList = new ArrayList<>();
        // 获取排除的项
        List<Uncheckeditems> noProblemItems = uncheckeditemsMapper.getEquipUncheckedItems(eqipNum,checkId,fourthId);
        for(int j=0;j<noProblemItems.size();j++){
            String unCheckedpName6 = newprefixsystemMapper.getName4ByName4Id(noProblemItems.get(j).getSixthId());
            int unCheckedFifthId = newprefixsystemMapper.getFather(noProblemItems.get(j).getSixthId()).getPreNum();
            String unCheckedpName5 = newprefixsystemMapper.getName4ByName4Id(unCheckedFifthId);
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("pName56",unCheckedpName6+"("+unCheckedpName5+")");
            map2.put("type","未涉及");
            map2.put("total",Double.parseDouble(newprefixsystemMapper.getPoint4ByPoint4Id(noProblemItems.get(j).getSixthId())));
            UncheckedList.add(map2);
        }
        map.put("UncheckedList",UncheckedList);
        //计算未涉及总分
        double allTotal=0;
        for(Map<String,Object> map3 : UncheckedList){
            allTotal+=(double) map3.get("total");
        }
        String allTotalPoint = df.format(allTotal);
        map.put("UncheckedTotal",allTotalPoint);
        list.add(map);
        return list;
    }

    /**
     * @author： wenyihan
     * @description：通过clientId获取片区信息
     * @date： 12:16 2020/7/12
     * @param： [clientId]
     * @return： java.lang.Object
    */
    @Override
    public List<Contracttaskaccept> getTaskOptionsByClientId(Integer contractId) {
        return contracttaskacceptMapper.getAllTaskInfo(contractId);
    }

    /**
     * @author： wenyihan
     * @description：获取设备检查体系下的第二级体系
     * @date： 16:04 2020/7/22
     * @return： java.util.List<com.whut.model.Prefixsystem>
    */
    @Override
    public List<Newprefixsystem> getSecondLevel() {
//        return prefixsystemMapper.getSecondByFirstName("设备检查");
        return newprefixsystemMapper.getSecondByFirstName("新设备检查");
    }

    /**
     * @author： wenyihan
     * @description：获取三四级体系
     * @date： 21:48 2020/7/22
     * @param： [number]
     * @return： java.util.List<com.whut.model.Prefixsystem>
    */
    @Override
    public List<Newprefixsystem> getThirdAndFourthLevel(int number) {
        return newprefixsystemMapper.getNextLevel(number);
    }

    /**
     * @author： wenyihan
     * @description：在ps表中通过number获取parameterName
     * @date： 23:55 2020/7/24
     * @param： [number]
     * @return： java.lang.String
    */
    @Override
    public String getParameterNameByNumber(int number) {
        return newprefixsystemMapper.getName4ByName4Id(number);
    }

    /**
     * @author: wangqirui
     * @Description: 根据工程id获取信息，即展示所有信息时调用的方法
     * @date: 2020/7/28 17:05
     * @param: projectName
     * @return: List<MachineInfo>
     */
    @Override
    public Object getMachineInfoRecordByProjectId(int projectId){
        List<MachineInfo> list = machineinfoMapper.getMachineInfoRecordByProjectId(projectId);
        return list;

    }

    /**
     * @author： wenyihan
     * @description：通过父id和parameterName查询当前选择体系的number
     * @date： 18:53 2020/7/31
     * @param： [pName, preNum]
     * @return： int
     */
    @Override
    public int getParameterNameByPreNumAndNum(String pName, int preNum) {
        return newprefixsystemMapper.getPSNumByPNameAndPreNum(pName, preNum);
    }

    /**
     * Author:yjh
     * Description:通过checkId查询所有设备评分信息,若无信息则复合查询并插入记录
     * Create date:2021/3/10 15:39
     * Param:[String check]
     * Return:Object
     * Modify[0]:2021/4/12,新增对新记录为空的情况下出现的bug补丁,
     */
    @Override
    public Object getAllEquipscoreBycheckId(String check){
        Integer check1 = Integer.parseInt(check);//转check为Integer
        List<Integer> oldkeys = equipscoreMapper.getmkeysByCheck(check1);//拿到所有的旧mkey
        List<Equipscore> listequipnew = getAllEquipscoreBycheck(check);//新数据
        List<Equipscore> listequipold = equipscoreMapper.getEquipscoreBycheckId(check1);//旧数据
        List<Integer> newkeys = new ArrayList<>();
        //使用每一条新数据查询表里可能存在的旧数据
        if (listequipnew!=null){
            for (Equipscore equipscoreitem:listequipnew){
                Integer mkey = equipscoreMapper.getmkeyByCheckTypeNum(equipscoreitem.getCheckId(),equipscoreitem.getEquipType(),equipscoreitem.getEquipNum());
                if (mkey==null){
                    //若没有找到对应新记录，添加一条
                    try {
                        equipscoreMapper.insertAll(equipscoreitem);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }else {
                    //若找到了，则更新meky以前的数据
                    updateData(equipscoreitem,mkey);
                }
                newkeys.add(mkey);
            }
            //若新数据比旧数据数量少，作删除
            if (listequipnew.size() < listequipold.size()){
                oldkeys.removeAll(newkeys);
                //删除表中未更新与插入的数据
                equipscoreMapper.deleteBymeky(oldkeys);
            }
        }else {
            //查询出的新数据为空，则删除之前的数据
            equipscoreMapper.deleteByCheckId(check1);
        }

        //查询最新的表中信息
        return equipscoreMapper.getEquipscoreBycheckId(check1);
    }

    /**
     * Author:yjh
     * Description:更新EquipScore表
     * Create date:2021/3/25 16:50
     */
    public void updateData(Equipscore equipscore,Integer mkey){
        try {
            HashMap<Object, Object> map1 = new HashMap<>();
            map1.put("projectId",equipscore.getProjectId());
            map1.put("checkId",equipscore.getCheckId());
            map1.put("projectName",equipscore.getProjectName());
            map1.put("equipType",equipscore.getEquipType());
            map1.put("equipNum",equipscore.getEquipNum());
            map1.put("equipScore",equipscore.getEquipScore());
            map1.put("risk0Point",equipscore.getRisk0Point());
            map1.put("risk1Point",equipscore.getRisk1Point());
            map1.put("risk2Point",equipscore.getRisk2Point());
            map1.put("risk3Point",equipscore.getRisk3Point());
            map1.put("risk4Point",equipscore.getRisk4Point());
            map1.put("risk1Num",equipscore.getRisk1Num());
            map1.put("risk2Num",equipscore.getRisk2Num());
            map1.put("risk3Num",equipscore.getRisk3Num());
            map1.put("risk4Num",equipscore.getRisk4Num());
            map1.put("mkey",mkey);
            equipscoreMapper.updateEquipScoreByPrimaryKey(map1);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * Author:yjh
     * Description:将对象转为map
     * Create date:2021/3/12 12:14
     * Param:[Object args]
     * Return:Map<String, Object>
     * Modify[]:,,
     */
    public static Map<String, Object> parseObj2Map(Object args) {
        return Arrays.stream(BeanUtils.getPropertyDescriptors(args.getClass()))
                .filter(pd -> !"class".equals(pd.getName()))
                .collect(HashMap::new,
                        (map, pd) -> map.put(pd.getName(), ReflectionUtils.invokeMethod(pd.getReadMethod(), args)),
                        HashMap::putAll);
    }
    /**
     * Author:yjh
     * Description:根据check与equiptype查询equipscore
     * Create date:2021/3/11 15:53
     * Param:[String check,String equipType]
     * Return:listequip
     * Modify[]:,,
     */
    @Override
    public Object getEquipscoreBycheckIdEquipType(String check,String equipType){
        Integer check1 = Integer.parseInt(check);//转check为Integer
        Integer equiptype1 = Integer.valueOf(equipType);
        List<Equipscore> listequipe = equipscoreMapper.getEquipscoreBycheckIdEquipType(check1,equiptype1);
//        HashMap<String, Object> map1 = new HashMap<>();
        List<Object> result = new ArrayList<>();
        for (Equipscore itemequipscore:listequipe){
            List<Float> fourthRiskList = new ArrayList<>();
            fourthRiskList.add(itemequipscore.getRisk0Point());
            fourthRiskList.add(itemequipscore.getRisk1Point());
            fourthRiskList.add(itemequipscore.getRisk2Point());
            fourthRiskList.add(itemequipscore.getRisk3Point());
            fourthRiskList.add(itemequipscore.getRisk4Point());
            int maxIndex = newFuzzyService.getCombinedMaxRiskIndex(fourthRiskList);
            String itemRisk = "";
            switch (maxIndex) {
                case 0:
                    itemRisk = "可忽略风险";
                    break;
                case 1:
                    itemRisk = "可容忍风险";
                    break;
                case 2:
                    itemRisk = "可接受风险";
                    break;
                case 3:
                    itemRisk = "不可接受风险";
                    break;
                case 4:
                    itemRisk = "拒绝接受风险";
                    break;
                default:
            }
            Map<String, Object> stringObjectMap = parseObj2Map(itemequipscore);
            List<Integer> riskNums = new ArrayList<>();
            List<Integer> problems = new ArrayList<>();
            if(itemequipscore.getRisk1Num()!=0){
                riskNums.add(1);
                problems.add(itemequipscore.getRisk1Num());
            }
            if(itemequipscore.getRisk2Num()!=0){
                riskNums.add(2);
                problems.add(itemequipscore.getRisk2Num());
            }
            if(itemequipscore.getRisk3Num()!=0){
                riskNums.add(3);
                problems.add(itemequipscore.getRisk3Num());
            }
            if(itemequipscore.getRisk4Num()!=0){
                riskNums.add(4);
                problems.add(itemequipscore.getRisk4Num());
            }
            stringObjectMap.put("riskNums",riskNums);
            stringObjectMap.put("problems",problems);
            stringObjectMap.put("risklevel",itemRisk);
//            System.out.println("problems===================================================");
//            for (Integer item:problems){
//                System.out.println("    fdsa " + item);
//            }
            result.add(stringObjectMap);
        }
        return result;
    }
    /**
     * Author:yjh
     * Description:通过checkId得到以设备编号分类的equipScore表
     * Create date:2021/3/8 13:04
     * Param:[String check]
     * Return:List<Equipscore>
     * Modify[]:,,
     */
    public List<Equipscore> getAllEquipscoreBycheck(String check1){
        List<ProblemCollectDetail> listcheck = newProblemCollectDetailMapper.getAllInfoByCheck(check1);
        List<String> listequipType = new ArrayList<>();//设备类型列表,[8257,8344]
        List<String> listequipNum = new ArrayList<>();//设备编号,[1#门式起重机...]
        int projectId = 0;//查询得到的单个项目编号
        for (ProblemCollectDetail itemcheck:listcheck){
            if(projectId != itemcheck.getProjectId()){//去除listcheck中projectId重复值
                projectId = itemcheck.getProjectId();
                List<MachineInfo> listTemp = machineinfoMapper.getequipTypeByProject(projectId);
                for (MachineInfo itemproject:listTemp){
                    if (itemproject == null){//方法安全性，避免报错
                        System.out.println("!ERRORE");
                        break;
                    }
                    String equipType;//查询得到的单个设备类型
                    if (!listequipType.contains(equipType = itemproject.getEquipType().toString())){//去除listproject中projectType重复值
                        listequipType.add(equipType);
                    }
                    listequipNum.add(itemproject.getEquipNum());
                }
            }
        }
        String projectname = contracttaskprojectMapper.getProjectNameByProjectId(projectId);
        if (listequipType.size() == 0){
            return null;
        }
        List<ProblemCollectDetail> listresByCT = newProblemCollectDetailMapper.getAllInfoByCheckThirdId(listequipType,check1);
        //由所查设备类型找到对应的检查信息并保存
        List<Equipscore> listequipscore = new ArrayList<>();//Equipscore列表
        for (String itemequip:listequipNum) {//遍历设备编号
            for (ProblemCollectDetail itemPcd : listresByCT) {//遍历查询结果
                Equipscore e = new Equipscore();//Equipscore对象
                if (itemPcd.getCheckPart().equals(itemequip)){
                    e.setAllInfo(itemPcd.getProjectId(),itemPcd.getCheckId(),projectname,itemPcd.getThirdId(),itemequip);
                    listequipscore.add(e);
                    break;
                }
            }
        }
        //筛选特征值的问题数量
        for (Equipscore itemequipscore:listequipscore){
            int problemnum1 = newProblemCollectDetailMapper.getProblemNumByCheckIdEquipNumRiskPoint(itemequipscore.getCheckId(),"%"+itemequipscore.getEquipNum()+"%","1");
            int problemnum2 = newProblemCollectDetailMapper.getProblemNumByCheckIdEquipNumRiskPoint(itemequipscore.getCheckId(),"%"+itemequipscore.getEquipNum()+"%","2");
            int problemnum3 = newProblemCollectDetailMapper.getProblemNumByCheckIdEquipNumRiskPoint(itemequipscore.getCheckId(),"%"+itemequipscore.getEquipNum()+"%","3");
            int problemnum4 = newProblemCollectDetailMapper.getProblemNumByCheckIdEquipNumRiskPoint(itemequipscore.getCheckId(),"%"+itemequipscore.getEquipNum()+"%","4");
            List<Integer> problemlist = new ArrayList<>();
            problemlist.add(problemnum1);//加入特征值为1的问题数量
            problemlist.add(problemnum2);//特征值为2的问题数量
            problemlist.add(problemnum3);//...
            problemlist.add(problemnum4);//...
//            for (int i:problemlist){
//                System.out.println("233233:"+i);
//            }
            List<Float> risks = newFuzzyService.findMemberShipByRisksNum(problemlist);//返回隶属度
            Float score = newFuzzyService.calcPoint(risks);//根据隶属度返回分数
            itemequipscore.setScoreAndRisks(score,risks,problemlist);//对象添加分数
        }
        //test-start
//        System.out.println("======================================================================5");
//        for (Equipscore item:listequipscore){
//            item.showAll();
//        }
//        for (String item:listequipType){
//            System.out.println("设备类型："+item);
//        }
//        for (String item:listequipNum){
//            System.out.println("设备类型名："+item);
//        }
        //test-end
        return listequipscore;
    }

    /**
     * Author:yjh
     * Description:分裂checkPart,使每一个设备类型能够匹配checkPart中每一个值
     * Create date:2021/3/25 15:59
     * Param:[]
     * Return:
     * Modify[0]:2021/4/12,废弃,
     */
//    public boolean isEqualCheckPartAndEquipnum(String checkPart,String equipnum){
//        String[] splitcheckpart = checkPart.split(",");
//
//        for (String item:splitcheckpart){
//            System.out.println(item);
//        }
//        return true;
//    };

    /**
     * Author:yjh
     * Description:通过委托+任务+项目（checkId）获取所有设备信息
     * Create date:2021/3/4 14:27
     * Param:[client,task,check,startTime,endTime]
     * Return:设备信息
     * Modify[0]:2021/4/12,未使用,
     */
    @Override
    public Object getAllequipInfoByClientTaskCheckid(String client, String task, String check, String startTime, String endTime) {
        JSONArray jsonArray3 = JSONArray.parseArray(check);
        Object a = jsonArray3.get(0);
        System.out.println("aaaaaaaaa"+a.toString());
        return null;
    }
    /**
     * Author:yjh
     * Description:通过checkId查询equipType和评分均值
     * Create date:2021/3/11 17:16
     * Param:[String check]
     * Return:List<String>
     * Modify[]:,,
     */
    @Override
    public Object getEquiptypeByCheckId(String check){
        Integer check1 = Integer.parseInt(check);//转check为Integer
        List<Integer> listequiptype = equipscoreMapper.getEquipTypeBycheckId(check1);
        Map<Integer, String> listName = new HashMap<>();
        for (Integer item:listequiptype){
            listName.put(item,newprefixsystemMapper.getName4ByName4Id(item));
        }
        if (listName.size()==0){
            return null;
        }
        return listName;
    }
}


